package com.shujia;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;

public class Demo06Set {
    Jedis jedis;

    @Before
    // 在@Test注解方法之前会运行一次
    public void init() {
        jedis = new Jedis("master", 6379);
    }

    @Test
    public void sADD() {
        // 1 2 3 4 5
        jedis.sadd("s1","1","2","3","3","4","4","1","5");
        // 3 4 5 6 7
        jedis.sadd("s2","5","5","6","3","4","4","7","5");
    }

    @Test
    public void sMembers(){
        for (String s1 : jedis.smembers("s2")) {
            System.out.print(s1+" ");
        }
        System.out.println();
    }

    @Test
    public void setOp(){
        for (String s : jedis.sinter("s1", "s2")) {
            System.out.print(s+" ");
        }
        System.out.println();

        for (String s : jedis.sunion("s1", "s2")) {
            System.out.print(s+" ");
        }
        System.out.println();

        for (String s : jedis.sdiff("s1", "s2")) {
            System.out.print(s+" ");
        }
        System.out.println();
    }

    @Test
    public void isMember(){
        System.out.println(jedis.sismember("s1","7"));
        System.out.println(jedis.sismember("s1","1"));
    }


    @After
    // 在@Test注解方法之后会运行一次
    public void close() {
        jedis.close();
    }
}
